package com.utp.soft6.model;

import java.io.Serializable;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;

import com.utp.soft6.model.enteties.Login;

public final class LoginDAO {

	private Session session;

	public LoginDAO(Session session) {
		this.session = session;

	}
	
	
	
	public String find(Login id) {
		String login = null;
		try {
		login = (String) session.load(Login.class, id);
		} catch (Exception e) {
		e.printStackTrace();
		}
		return login;
		}
	


	// Buscando el noc

	public  List<Login> findAll() {
		List<Login> list = null;
		list = findByHQL("FROM clientes");
		return list;
	}

	
	public Login findByCorreo(String correo) {
		Login login = null;

		try {
			Query query = session
					.createQuery("SELECT correo FROM clientes a WHERE a.correo=:correo");
			query.setParameter("correo", correo);
			login = (Login) query.uniqueResult();

		} catch (HibernateException e) {
			e.printStackTrace();

		}

		return login;
	}

	@SuppressWarnings("unchecked")
	public List<Login> findByHQL(String hql) {
		List<Login> list = null;
		try {
			Query query = session.createQuery(hql);
			list = (List<Login>) query.list();
		} catch (HibernateException e) {
			e.printStackTrace();
		}
		return list;
	}

}
